package _工具包整理._判断对象相等;

import org.junit.Test;

public class EqualsTest {

    @Test
    public void test001() {
        // ==
        Integer a001 = null;
        Integer a002 = null;
        System.out.println(a001 == a002);// null 指向同一地址

        Integer a003 = 2;
        Integer a004 = null;
        System.out.println(a003 == a004);

        Integer a005 = 2;
        Integer a006 = 2;
        System.out.println(a005 == a006);// 两个 同一类型的包装类 指向不同地址

        int a007 = 2;
        Integer a008 = 2;
        System.out.println(a007 == a008);// == 在比较包装类 和 基本类 的时候，会自动拆箱
        Long a009 = 2L;
        System.out.println(a007 == a009);

        int a017 = 8882;
        Integer a018 = 8882;
        System.out.println(a007 == a008);// == 在比较包装类 和 基本类 的时候，会自动拆箱
        Long a019 = 8882L;
        System.out.println(a007 == a009);
        // System.out.println(a018 == a009); 报错  不可比较的类型

        System.out.println("-----");
        int a011 = 8882;
        double a012 = 8882;
        long a013 = 8882;
        System.out.println(a011 == a012);// 基本类型，直接比较数值
        System.out.println(a011 == a013);
        System.out.println(a012 == a013);
        System.out.println(a012 == a019);
    }

    @Test
    public void test002() {
        // equals
        Integer a005 = 2;
        Integer a006 = 2;
        System.out.println(a005.equals(a006));

        Integer a003 = 2;
        Long a004 = 2L;
        System.out.println(a003.equals(a004));// 包装类不同，false

        Integer a013 = 2;
        int a014 = 2;
        System.out.println(a013.equals(a014));// equals 会对 基本类型自动装箱

        Integer a001 = null;
        Integer a002 = null;
        System.out.println(a001.equals(a002));
    }

}
